//
//  TextFieldCell.m
//  TiantuLogistics
//
//  Created by zhishi.zhaochunlin on 16/5/11.
//  Copyright © 2016年 tiantu. All rights reserved.
//

#import "TextFieldCell.h"

@implementation TextFieldCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
   
    self.containerTextField.delegate = self;
    self.requestLable.textColor = kPriceColor;
    self.titleLabel.clipsToBounds = self.containerTextField.clipsToBounds = self.requestLable.clipsToBounds = YES;
    self.backgroundColor = kWhiteColor;
}
#pragma mark UITextFieldDelegate
//当输入框中文字发生变化,该方法会被触发(只要改变,就会触发)

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString *newStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
    if(newStr.length >20){
        
        if (![string isEqualToString:@""]) {
            return NO;
        }
        
    }
    
    if ([string isEqualToString:@""]) {
        //这个是汉语联想的时候的他会出现的，第一次暂时让其联想，下次输入就不能联想了，因为第一次联想它不给自己算lenth，下次再联想词汇就会算上上次输入的，这个是苹果自己的BUG 如果是textfiled，一样 检测每个字符的变化。
        
        return YES;
        
    }
    if (range.location>=20|| textField.text.length>=20)
    {
        return  NO;
    }
    
    if ([string isEqualToString:@"\n"]) {
        [textField resignFirstResponder];
        return NO;
        
    }
    
    if ((textField.text.length - range.length + string.length) > 20)
    {
        return NO ;
    }
    return YES;
}


- (void)initData:(NSString*)placeHolder titleLabelText:(NSString *)text1 textFtext:(NSString *)text {
    _titleLabel.text =text1;
    _containerTextField.text = text;
    _containerTextField.placeholder = placeHolder;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
